/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import dao.ProductDAO;
import dao.ProductDAOImpl;
import entity.Product;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author OkSa Bawu
 */
public class Tester {

    public static void main(String args[]) {
        EntityManagerFactory emf =
                Persistence.createEntityManagerFactory("persistence03PU");
        EntityManager em = emf.createEntityManager();

//        Product p = new Product();
//        p.setNama("Keyboard");
//        p.setKeterangan("No Keterangan");
//        p.setPrice(100000);

        ProductDAO dao = new ProductDAOImpl(em);
        try {
            Product p = dao.get(3L);
            p.setNama("Monitor");
            dao.update(p);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //Product p = null;

//        em.getTransaction().begin();
//        //em.remove(em.find(Product.class, 1L));
//        List<Product> data = 
//                em.createQuery("SELECT p FROM Product p WHERE p.nama LIKE :param")
//                .setParameter("param", "Monitor").getResultList();
//        System.out.println(data.size());
//        em.getTransaction().commit();
    }
}
